<template>

  <catEvReviewDetail ref="catEvReviewDetail" />

  <div class="body">
    <div class="left-board">
      <div class="logo">{{ title }}</div>
      <div class="operate">
      </div>
    </div>

    <div style="display:flex">
      <div style="margin-left:6px;line-height:30px">评价类别：</div>

      <el-select clearable v-model="form.typeId" placeholder="请选择评价类别">
        <el-option v-for=" item in typeList" :value="item.id" :label="item.name"></el-option>
      </el-select>
      <div style="margin-left:6px;line-height:30px">评价时段：</div>
      <el-date-picker v-model="form.daterange" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
        range-separator="到" unlink-panels="true" start-placeholder="开始时间" end-placeholder="结束时间">
      </el-date-picker>
      <el-button style="margin-left:10px" type="primary" plain @click="search">筛选</el-button>

      <el-button type="info" plain @click="closeAll">关闭</el-button>

    </div>

    <div id="main" style="width: 100%; height: 500px;margin-top:10px"></div>
    <h3>评价列表</h3>
    <el-table size="small" :data="list" style="width: 90%;margin-left: 5%;" border :row-class-name="tableRowClassName">
      <el-table-column type="index" width="100" label="序号" />
      <el-table-column prop="title" label="评价标题" />
      <el-table-column prop="score" label="总得分" />
      <el-table-column label="操作" width="320px">
        <template style="display: block" #default="scope">
          <el-button size="small" type="warning" @click="cat(scope.row)">得分明细
          </el-button>
        </template>
      </el-table-column>
      <template v-slot:empty>
        <el-empty description="暂无数据"></el-empty>
      </template>
    </el-table>

    <div id="main3" style="width: 100%; height: 600px;margin-top:60px"></div>
    <div id="main2" style="width: 100%; height: 600px;margin-top:60px"></div>


  </div>
</template>
<script >
import catEvReviewDetail from "@/components/evaluate/catEvReviewDetail.vue";
import draggable from "vuedraggable";
import { ElMessage, ElMessageBox } from "element-plus";
import { Eleme, Delete, Remove, Plus, CopyDocument } from "@element-plus/icons-vue";

import { httpService } from "@/utils/httpService";
import { getCurrentInstance } from "vue";


let myChart;
let myChart2;
let myChart3;

export default {
  name: "NoFound",

  setup() {
    const { proxy } = getCurrentInstance()
    const echarts = proxy.$echarts
    console.log(echarts)
    return {
      echarts
    }
  },
  mounted() {
    this.uuid = this.$route.query.p;
    this.title = this.$route.query.q;
    // this.queryById();
    this.getReviewList();
    this.getEvTypeList();
    this.queryAllCountByStudentNumber();
  },

  watch: {

  },

  components: {
    draggable,
    Eleme,
    Delete, Remove,
    Plus,
    ElMessageBox,
    httpService,
    CopyDocument, catEvReviewDetail, getCurrentInstance
  },
  props: {
    value: {
      type: String,
      default: "",
    },
    disabled: {
      type: Boolean,
      default: false,
    },

  },
  data() {
    return {
      typeList: [],
      rightValue: [],
      rightValueStudent: [],
      teacherPageInfo: {},
      studetPageInfo: {},
      title: "",
      isTimeControl: 0,
      isPassword: 0,
      uuid: "",
      isEmpty: true,
      list: [],
      indexGlobal: -1,
      questionnaireId: 0,
      form: {
        daterange: "",
        typeId: ""
      },
      option: {
        title: {
          text: '评价成绩'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [],
            type: 'line',
            smooth: true,
            label: {
              normal: {
                show: true,
                position: 'top'
              }
            },
          }
        ]
      },
      option2: {
        title: {
          text: '评价点占比'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} 次 ({d}%)'

        },
        legend: {
          show:false,
          type: 'scroll',
          orient: 'vertical',
          right: 0,
          top: 20,
          bottom: 20,
        },
        series: [
          {
            name: '评价点占比',
            type: 'pie',
            radius: ['20%', '70%'],
            center: ['50%', '50%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: true,
              position: 'bottom'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '20',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [

            ]
          }
        ]
      },
      option3: {
        title: {
          text: '评价点得分占比'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} 分 ({d}%)'

        },
        legend: {
          show:false,

          type: 'scroll',
          orient: 'vertical',
          right: 0,
          top: 20,
          bottom: 20,
        },
        series: [
          {
            name: '评价点得分占比',
            type: 'pie',
            radius: ['50%', '70%'],
            center: ['50%', '50%'],

            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 4,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: true,
              position: 'bottom'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '20',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [

            ]
          }
        ]
      }
    };
  },
  methods: {
    search(){
      this.getReviewList();
      this.queryAllCountByStudentNumber();
    },
    getEvTypeList() {
      httpService(
        "/javaApi/evType/queryAll",
        {
        },
        "get"
      ).then((data) => {
        this.typeList = data;
      });
    },
    cat(obj) {
      this.$refs.catEvReviewDetail.title = "得分明细"
      this.$refs.catEvReviewDetail.total = obj.score; 
      this.$refs.catEvReviewDetail.queryAllByStudentNumberReviewId(obj.id, this.uuid);
      // this.$refs.catEvReviewDetail.getBaseClassinfoList();
      this.$refs.catEvReviewDetail.dialogFormVisible = true;
      this.$refs.catEvReviewDetail.addNewsInfoForm.title = this.title;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    setChart() {
      if (myChart != null && myChart != "" && myChart != undefined) {
        myChart.dispose();//销毁
      }
      myChart = this.echarts.default.init(document.getElementById('main'));

      myChart.setOption(this.option)
    },

    setChart2() {
      if (myChart2 != null && myChart2 != "" && myChart2 != undefined) {
        myChart2.dispose();//销毁
      }
      myChart2 = this.echarts.default.init(document.getElementById('main2'));
      myChart2.setOption(this.option2)
    },
    setChart3() {
      if (myChart3 != null && myChart3 != "" && myChart3 != undefined) {
        myChart3.dispose();//销毁
      }
      myChart3 = this.echarts.default.init(document.getElementById('main3'));

      myChart3.setOption(this.option3)
    },
    queryById() {
      httpService(
        "/javaApi/evReview/queryById",
        "id=" + this.uuid,
        "post"
      ).then((data) => {
        if (data != "") {
          this.title = data.title;
        } else {
          this.$router.push({
            path: "/noFound",
          });
        }
      });
    },

    getReviewList() {
      httpService(
        "/javaApi/evReview/queryAllByStudentNumber",
        {
          studentNumber: this.uuid,
          "timeRange": this.form.daterange,
          "typeId": this.form.typeId,

        },
        "get"
      ).then((data) => {
        if (data) {
          this.list = data
          let xAxisData = [];
          let seriesData = [];

          for (var i = 0; i < data.length; i++) {
            xAxisData.push(data[i].title);
            seriesData.push(data[i].score);
          }
          this.option.xAxis.data = xAxisData;
          this.option.series[0].data = seriesData;
          this.setChart()

        }
      });
    },
    queryAllCountByStudentNumber() {
      httpService(
        "/javaApi/evReview/queryAllCountByStudentNumber",
        {
          studentNumber: this.uuid,
          "timeRange": this.form.daterange,
          "typeId": this.form.typeId,

        },
        "get"
      ).then((data) => {
        if (data) {
          let seriesData = [];
          let seriesData3 = [];

          for (var i = 0; i < data.length; i++) {
            seriesData.push({ value: data[i].count, name: data[i].title });
            seriesData3.push({ value: data[i].score, name: data[i].title });

          }
          this.option2.series[0].data = seriesData;
          this.option3.series[0].data = seriesData3;

          this.setChart2()
          this.setChart3()

        }
      });
    },

    // 可以添加一些自己的自定义事件，如清空内容
    clear() {
      this.contentValue = "";
    },



    handleChange(
      value,
      direction,
      movedKeys
    ) {
      console.log(value, direction, movedKeys)
    },
    handleChangeStudent(
      value,
      direction,
      movedKeys
    ) {
      console.log(value, direction, movedKeys)
    },

    closeAll() {

      window.opener = null;
      window.open("", "_self");
      window.close();
    },


  },
};
</script>
<style>
.warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-light-9);
}

.success-row {
  --el-table-tr-bg-color: var(--el-color-success-light-9);
}
</style>
<style>
.el-transfer-panel {
  width: 230px;
}

.el-tabs__content {
  border-left: 1px solid #dedede;
}

.el-tabs__item.is-active.is-focus {
  border: 0px solid red;
}

.el-rate__icon {
  font-size: 30px;
}

.el-tabs__header {
  padding: 0;
  position: relative;
  margin: 0 0 0px;
}

.el-radio {
  line-height: 32px;
}

.m-empty {
  background: url(../../assets/center_bg_2.png) no-repeat;
  background-repeat: no-repeat;
  background-position: center;
}

.el-switch__label span {
  line-height: 20px;
}

.el-switch {
  margin-left: 10px;
}

.el-divider {
  margin: 0px;
}
</style>
<style scoped>
.dateTimeRange {
  margin-bottom: 16px;
}

.mb-right {
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 0px;
}

.ghost {
  border-top: 4px solid #409EFF;
}

.body {
  background: white;
  width: 90%;
  margin: 0 auto;
  padding-top: 20px;
  padding-bottom: 100px;
}

h3 {
  color: #444444;
}

.delete-btn {
  margin-top: 10px;
}

.add-btn {
  margin-left: 80px;
}

.index {
  padding: 10px 10px 20px 0px;
  color: #409eff;
}

.m-line {
  background: #f2f2f2;
  height: 1px;
  margin-bottom: 10px;
}

.index-left {
  padding: 5px;
}

.delete {
  float: right;
  cursor: pointer;
  color: #f56c6c;
  padding: 5px;
  margin: 15px;
}

.delete-children {
  float: right;
  cursor: pointer;
}


.select-bg {
  border: 1px solid #409EFF;
  color: #606255;
  margin-top: 10px;
  background: white;
  border-radius: 4px;
}

.unselect-bg {
  border: 1px dashed #409EFF;
  background: white;
  margin-top: 10px;
  color: #606255;
  border-radius: 4px;
}

.list-group-item-right {
  cursor: move;
  /* display: flex; */
  padding: 20px;
}

.list-group-item-right:hover {
  background: white;
  border-radius: 6px;
}


.operate {
  font-weight: 600;
  height: 40px;
  line-height: 40px;
  float: right;
  text-align: right;
  font-size: 17px;
  padding-left: 20px;
  white-space: nowrap;
  background: white;
  padding-right: 20px;
}

.logo {
  color: #409EFF;
  font-weight: 600;
  height: 40px;
  line-height: 40px;
  font-size: 20px;
  padding-bottom: 20px;
  padding-left: 6px;
  white-space: nowrap;
}

.logo-bottom {
  border-top: solid #dedede 1px;
  border-right: solid #dedede 1px;
  height: calc(100vh - 60px);
  padding: 10px;
}

.sub-title {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  min-width: 100px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.list-group-item-left {
  cursor: move;
  width: 50%;
}

.list-group-item-left .components-item {
  display: inline-block;
  width: calc(100% - 8px);
  margin: 4px;
  -webkit-transition: -webkit-transform 0ms !important;
  transition: -webkit-transform 0ms !important;
  transition: transform 0ms !important;
  transition: transform 0ms, -webkit-transform 0ms !important;
}

.item {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
}

.components-body:hover {
  border: 1px solid #409EFF;
  color: #409EFF;
}

.components-body {
  color: #707070;
  border: 1px solid #eaeaea;
  background-color: #fff;
  padding: 8px 10px;
  font-size: 16px;
  cursor: move;
  text-align: center;
  border-radius: 3px;
}

.components-title {
  font-size: 16px;
  color: #222;
  margin: 10px 2px;
  font-weight: bold;
}

.left-board {}

.center-board {
  width: auto;
  background: white;
  text-align: center;
  padding: 20px;
  border-radius: 6px;
  opacity: 1;
  background: #FFFFFF;
  box-shadow: 0px 0px 4px 0px rgb(0 0 0 / 8%), 0px 2px 6px 0px rgb(0 0 0 / 6%), 0px 4px 8px 2px rgb(0 0 0 / 4%);
}

.draggable {
  height: calc(100vh - 80px);
  width: auto;

  overflow: scroll;
  border-top: 1px solid #dedede;
  padding: 10px 10px 30px 10px;
}


.right-content {
  width: calc(100% - 37px);
  height: calc(100vh - 60px);
  padding: 10px;
  overflow: auto;
}

.el-form-item--default {
  --font-size: 14px;
  --el-form-label-font-size: var(--font-size);
  margin-bottom: 18px;
  width: 100%;
}

.esign {
  max-width: 1000px;
  margin: auto;
  padding: 10px;
}

.esigh-btns button {
  color: #fff;
  height: 40px;
  width: 100px;
  font-size: 16px;
  margin-right: 10px;
  outline: none;
  border-radius: 4px;
  background: #f60;
  border: 1px solid transparent;
}

.esigh-btns button:active {
  color: #fff;
  box-shadow: 0px 0px 50px orangered inset;
}

.esigh-result {
  margin-top: 10px;
}

.esigh-result img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #ececee;
}

.esignature {
  margin: 10px 0;
  border: 1px solid #79bbff;
  border-radius: 4px;
}

.el-tabs__header {
  padding: 0;
  position: relative;
  margin: 0px;
}

.children-item {
  padding-left: 10px;
}

h3 {
  padding-left: 10px;
}

.demo-form-inline {
  display: flex;
}
</style>

